<?php
defined('SEJUJOPEFDNGJSL') or exit('Access denied');
function geteqval($arr){   //辅助函数，类似三元运算符
	if($arr[0]==$arr[1]){
		return $arr[2];
	}else{
		return $arr[3];
	}
}
//取得匹配状态array($v["helper_confirm_amount"],$v["amount"],$v['status'],$v["giveh_eviup_time"],$v['get_helper_unconfirm'])
function getpeistatus($arr){
	if(!empty($arr[3])){
		return '<span style="color:#ff6600">交易完成</span>';
	}elseif($arr[2]==0){
		if($arr[4] == 1){
			if($arr[0] != $arr[1]){
				return '<span style="color:#33AB47">正在调度</span>';
			}else{
				return '<span style="color:#49AB47">部分交易中断</span>';
			}
		}else{
			if($arr[0] > 0 && $arr[0] != $arr[1]){
				return '<span style="color:#33AB47">正在调度</span>';
			}else{
				return '<span style="color:#49AB47">等待匹配</span>';
			}
		}
	}elseif($arr[2]==1){
		if($arr[4] == 1){
			if($arr[0] != $arr[1]){
				return '<span style="color:#49AB47">部分交易中断</span>';
			}else{
				return '<span style="color:#ff6600">交易完成</span>';
			}
		}else{
			if($arr[0] > 0 && $arr[0] != $arr[1]){
				return '<span style="color:#33AB47">正在调度</span>';
			}elseif($arr[0] == $arr[1]){
				return '<span style="color:#ff6600">交易完成</span>';
			}else{
				return '<span style="color:#49AB47">等待打款->确认</span>';
			}
		}
	}elseif($arr[2]==2){
		return '<span style="color:purple">配对已过期</span>';
	}elseif($arr[2]==3){
		return '<span style="color:#000">已取消</span>';
	}
}

//$v["receiver_confirm_amount"],$v["get_help_amount"],$v['status'],$v['receiver_confirm_time'],$v['matched_amount']
function getpeistatus1($arr){
	if(!empty($arr[3])){
		return '<span style="color:#ff6600">交易完成</span>';
	}elseif($arr[2]==0){
		if($arr[4] > 0){
			return '<span style="color:#77f">正在调度</span>';
		}else{
			return '<span style="color:#49AB47">等待匹配</span>';
		}
	}elseif($arr[2]==1){
		return '<span style="color:#77f">等待收款</span>';
	}elseif($arr[2]==2){
		return '<span style="color:purple">配对已过期</span>';
	}elseif($arr[2]==3){
		return '<span style="color:#000">已取消</span>';
	}

}

function get_right_class($zhuangtai){
	if(strstr($zhuangtai,"等待匹配")){
		return "order-status-0";
	}elseif(strstr($zhuangtai,"等待收款") || strstr($zhuangtai,"等待打款") || strstr($zhuangtai,"等待收款人确认")){
		return "order-status-1";
	}elseif(strstr($zhuangtai,"交易完成")){
		return "order-status-2";
	}elseif(strstr($zhuangtai,"已取消")){
		return "order-status-3";
	}elseif(strstr($zhuangtai,"配对已过期")){
		return "order-status-4";
	}
}

function random_filename()
{
        $str = '';
        for($i = 0; $i < 9; $i++)
        {
            $str .= mt_rand(0, 9);
        }

        return time().$str;
}


function getcunstatus($arr){
	if($arr["is_overdate"]==1){
		return "配对过期";
	}elseif($arr["is_finnished"]==0&&empty($arr["evidence_upload_time"])){
		return "匹配成功等待打款";
	}elseif($arr["is_finnished"]==0&&!empty($arr["evidence_upload_time"])){
		return "等待收款方确认";
	}elseif($arr["is_finnished"]==1){
		return "已完成";
	}
}

function getcunstatus1($arr){
	if($arr["is_overdate"]==1){
		return "配对过期";
	}elseif($arr["is_finnished"]==0&&empty($arr["evidence_upload_time"])){
		return "等待提供帮助人付款";
	}elseif($arr["is_finnished"]==0&&!empty($arr["evidence_upload_time"])){
		return "对方已付款尽快确认收款";
	}elseif($arr["is_finnished"]==1){
		return "已完成";
	}
}


function historygo(){
	echo "<script>history.go(-1)</script>";
}

function locationurl($url){
	echo '<script type="text/javascript">window.location.href="'.$url.'"</script>';
	exit;
}
//得到随机激活码
function createRandomStr($length){
	$str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';//62个字符
	$strlen = strlen($str);
	while($length > $strlen){
		$str .= $str;
		$strlen += $strlen;
	}
	$str = str_shuffle($str);
	$str1 = time();
	$str2 = substr($str1,9,1).substr($str1,7,1).substr($str1,6,1).substr($str1,4,1).substr($str1,2,1).substr($str1,8,1).substr($str1,3,1).substr($str1,1,1).substr($str1,5,1).substr($str1,-1);
	$str3 = substr($str,0,$length).$str2;
	$str4 = str_shuffle($str3);
	return $str4;
}
function geturls(){
	return substr($_SERVER['HTTP_REFERER'],0,strlen($_SERVER['HTTP_REFERER'])-strlen(strrchr($_SERVER['HTTP_REFERER'],"/")));
}


function getcharnums($s){
	$s=trim($s);
	if(empty($s)) return 0;

	preg_match_all('/./us', $s, $match);

	return count($match[0]);
}

function getstrval($arr){
	if(empty($arr[0])||empty($arr[1])) return $arr[3];
	if(strstr($arr[0],$arr[1])){
		return $arr[2];
	}else{
		return $arr[3];
	}
}


function getPath($path,$xin){
	if(empty($path)) $path="";
	return str_replace(",,",",",str_replace(",,",",",",".$path.",").$xin.",");
}

function getmenu($arr,$search,$t=0){
	$str='';
	foreach ($arr as $kr => $vr) {
		foreach ($vr as $k => $v) {
			if($v[0]==$search){
				if($t==1){
					$str=$kr;
				}else{
					$str=$k;
				}		
				break;
			}
		}
	}
	return $str;
}

function getfnum($num){
	if($num==""||empty($num)){
		return 0;
	}
	if(!is_numeric($num)){
		return 0;
	}
	return (floor($num*100)/100);
}

//字符串截取
function str_cut($str, $length, $start=0, $charset="utf-8", $suffix=true)
{
   $str = strip_tags($str);
   if(function_exists("mb_substr"))
   {
		   if(mb_strlen($str, $charset) <= $length) return $str;
		   $slice = mb_substr($str, $start, $length, $charset);
   }
   else
   {
		   $re['utf-8']   = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
		   $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
		   $re['gbk']          = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
		   $re['big5']          = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
		   preg_match_all($re[$charset], $str, $match);
		   if(count($match[0]) <= $length) return $str;
		   $slice = join("",array_slice($match[0], $start, $length));
   }
   if($suffix) return $slice."…";
   return $slice;
}

function getatricletype($a){
	$arr=array('公告','最新动态');
	if($a[0]==1){
		return $arr[$a[1]];
	}elseif($a[0]==2){
		$s.='<select name="attype" class="tselect">';
		foreach ($arr as $k => $v) {
			$s.='<option value="'.$k.'">'.$v.'</option>';
		}
		$s.='</select>';
		return $s;
	}elseif($a[0]==3){
		$s.='<select name="attype" class="tselect">';
		foreach ($arr as $k => $v) {
			$s.='<option value="'.$k.'" '.geteqval(array($k,$a[1],'selected','')).'>'.$v.'</option>';
		}
		$s.='</select>';
		return $s;
	}elseif($a[0]==4){
		return $arr;
	}

}

function a_bck($s){
	echo '<script type="text/javascript">artbck("'.$s.'");</script>';
	exit;
}
function jjjs(){
    echo '<script type="text/javascript" src="/public/home/js/jquery.min.js"></script>';
    echo '<script type="text/javascript" src="/public/home/js/layer/layer.js"></script>';
}
function msg_b($s){
// 	echo '<script type="text/javascript">alert("'.$s.'");history.go(-1);</script>';
    jjjs();
	echo "<script type=\"text/javascript\">
	$(function(){
        layer.alert(\"{$s}\", function(index){
        history.go(-1);
        layer.close(index);
        });
 });
 </script>";
	exit;
}
function msg_e($s){
	echo '<script type="text/javascript">alert("'.$s.'");window.location.href=window.location.href</script>';
	exit;
}

function msg_l($s,$u){
//     echo '<script type="text/javascript">alert("'.$s.'");window.location.href="'.$u.'"</script>';
    jjjs();
    echo "<script type=\"text/javascript\">
    $(function(){
    layer.alert(\"{$s}\", function(index){
    window.location.href=\"{$u}\";
    layer.close(index);
    });
    });
</script>";
	exit;
}

function chkusername($s){
	return preg_match("/^[a-zA-Z0-9][a-zA-Z0-9_]{3,14}$/u",$s);
}

function checkstr($strsql)
{     //检测字符串是否有注入风险
       
	$strsql=trim($strsql);
	$check=preg_match('/select|or|and|char|create|drop|database|table|insert|script|function|update|delete|exec|system|passthru|shell_exec|<|\`|\%|\"|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile/i',$strsql);
  
	if($check)
	{   
		if($strsql !='chark_sheng' ){
		   	echo "<script language='javascript'>alert('您输入的信息存在非法字符！');history.go(-1)</script>";
		   	exit;
		}
	}        
	return  $strsql;			          
			   
}

function getmessagetype($a){
	$arr=array('咨询','帮助','奖金','提现','充值','其他');
	if($a[0]==1){
		return $arr[$a[1]];
	}elseif($a[0]==2){
		$s='';
		foreach ($arr as $k => $v) {
			$s.='<label><input type="radio" name="emtype" value="'.$k.'" '.geteqval(array($k,0,'checked','')).'>&nbsp;'.$v.'</label>&nbsp;';
		}
		return $s;
	}elseif($a[0]==3){
		$s='';
		foreach ($arr as $k => $v) {
			$s.='<label><input type="radio" name="emtype" value="'.$k.'" '.geteqval(array($k,$a[1],'checked','')).'>&nbsp;'.$v.'</label>&nbsp;';
		}
		return $s;
	}elseif($a[0]==4){
		return $arr;
	}
}
function getinsertsql($arr,$t,$s=''){
	$key=array();
	$value=array();
	foreach ($arr as $k => $v) {
		$key[]=$k;
		$type=gettype($v);
		if((!empty($s)&&!($v==='')&&strpos("=".$s,$k))||($type=='integer'||$type=='double'||$type=='float')){
			$value[]=$v;
		}else{
			$value[]="'".$v."'";
		}
		
	}
	
	return "insert into $t(".implode(',',$key).") values(".implode(',',$value).")";
}

function getupdatesql($arr,$t,$c,$s=''){
	$r=array();
	foreach ($arr as $k => $v) {
		$type=gettype($v);    //获取变量的类型
		if((!empty($s)&&!($v==='')&&strpos("=".$s,$k))||($type=='integer'||$type=='double'||$type=='float')){   //判断是否为数值 
			$r[]="$k=$v";
			
		}else{       //字符串需要加''
			$r[]="$k='$v'";
		}

	}
	return "update $t set ".implode(',',$r)." where $c";
}

function chkpwd($arr,$t=0) {

	if($t){
		if(empty($arr[0])) return '请输入旧密码';
		if(empty($arr[1])) return '请输入新密码';
		if($arr[0]==$arr[1]) return '新密码和旧密码不能相同';
		if(strlen($arr[1]) < 8||strlen($arr[0]) < 8) return '密码最少8位，请修改';
	}else{
		if(empty($arr[0])) return '请输入密码';
		if(strlen($arr[0]) < 8) return '密码最少8位，请修改';
	}

	return true;
}


function getqueurl($ming,$num){     //改变链接的get参数和值
	$url= $_SERVER["QUERY_STRING"];
	$pattern="/".$ming."=[0-9]*/i";
	if(preg_match($pattern,$url))
	{
		return preg_replace($pattern,$ming."=".$num,UCENTERINDEX.'?'.$url);
	}else{
		if(empty($url))
			return UCENTERINDEX."?$ming=$num";
		else
			return UCENTERINDEX.'?'.$url."&$ming=$num";
	}	
}

function geturl(){
	return 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?".$_SERVER["QUERY_STRING"];
}

function getnums($v,$d=1){
	if(empty($v)) return $d;
	if(!is_numeric($v)) return $d;
	$v=floor(abs($v));
	if($v<1&&$d>0){
		$v=$d;
	}elseif($v<1&&$d<1){
		$v=0;
	}

	return $v;
}

function formatrmb($v){
	if(strstr($v,'.')){

		$s=explode('.',$v);
		if(empty($s[1])){
			return $s[0];
		}else{

			if(strpos($s[1],'0')===false){
				return $v;
			}else{
				$x1=substr($s[1],0,1);
				$x2=substr($s[1],1,1);
				if(empty($x1)&&!empty($x2)){
					return $s[0].'.0'.$x2;
				}elseif(!empty($x1)&&empty($x2)){
					return $s[0].'.'.$x1;
				}elseif(empty($x1)&&empty($x2)){
					return $s[0];
				}
			}
		}
	}else{
		return $v;
	}
}


function getsex($s){
	$arr=array('男','女','未知');
	return $arr[$s];
}

function getaccounttype($s=-1){
	$arr=array("可提现余额","利息收益","推广提成",'激活币','小金库','冻结小金库','无');
	if($s>=0)
		return $arr[$s];
	else
		return $arr;
}


function gethuantype($s=-1){
	$arr=array("可提现余额转激活币","小金库转现金币");
	if($s>=0)
		return $arr[$s];
	else
		return $arr;
}


function getzhuantype($s=-1){
	$arr=array("激活币账户");
	if($s>=0)
		return $arr[$s];
	else
		return $arr;
}

function getsessiontime(){
	$cha=time()-$_SESSION["savetime"];
	$fen=floor($cha/60);
	if(is_file(SITEROOT."/login/".$_SESSION['userid'].".txt")){
		$xx=file_get_contents(SITEROOT."/login/".$_SESSION['userid'].".txt");
	}else{
		$xx='';
	}
	if($fen>30 || (!empty($xx)&&!empty($_SESSION["logintime"])&&$xx!=$_SESSION["logintime"])){
		file_put_contents(SITEROOT."/login/".$_SESSION['userid'].".txt",'');
		session_unset();
		session_destroy();
		locationurl("index.php");
	}
	$_SESSION["savetime"]=time();
}

function getshouyistatus($arr){

	if($arr[0]==3){
		return "已取消";
	}elseif($arr[0]==2){
		return "已过期";	
	}elseif($arr[1]==0){
		return '<span style="color:#F7C640">收益中</span>';

	}elseif($arr[1]==1){
		return '<span style="color:#f00">收益结束</span>';
	}elseif($arr[1]==2){
		return '<span style="color:#f00">中断收益结束</span>';
	}
}


function getstatutype($v,$t){
	$arr=array(array('<span style="color:#E54C5B">待确认</span>','<span style="color:#707070">已确认</span>'),
			   array('<span style="color:#E54C5B">待确认</span>','<span style="color:#707070">已确认</span>','<span style="color:#29A2EB">已撤销</span>'),
			   array('<span style="color:#f00">待激活</span>','<span style="color:#707070">已激活</span>','<span style="color:#707070">已激活</span>'),
			   array('<span style="color:#f00">否</span>','<span style="color:#707070">是</span>'),
			   array('<span style="color:#f00">未阅</span>','<span style="color:#707070">已阅</span>'),
			   array('<span style="color:#f00">否</span>','<span style="color:#f00">待审核</span>','<span style="color:#707070">是</span>'),
			   array('<span style="color:#f00">未正式</span>','<span style="color:#ccc">已正式</span>','<span style="color:#707070">空单</span>'),
			   array('<span style="color:#74B673">等待</span>','<span style="color:#f00">完成</span>','<span style="color:#ddd">已过期</span>','<span style="color:#ddd">已取消</span>'),
			   array('<span style="color:#565656">收益中</span>','<span style="color:#f00">收益结束</span>','<span style="color:#f00">中断收益结束</span>'));
	switch ($t) {
		case 1:
			return $arr[0][$v];
		break;
		case 2:
			return $arr[1][$v];
		break;		
		case 3:
			return $arr[2][$v];
		break;	
		case 4:
			return $arr[3][$v];
		break;	
		case 5:
			return $arr[4][$v];
		break;	
		case 6:
			return $arr[5][$v];
		break;	
		case 7:
			return $arr[6][$v];
		break;	
		case 8:
			return $arr[7][$v];
		break;	
		case 9:
			return $arr[8][$v];
		break;																
	}
}

function formatdate($d,$t=0){
	$arr=array('Y-m-d H:i:s','Y-m-d','m-d H:i:s');
	if(empty($d)) return '';
	if(date($arr[1],$d)=='1970-01-01') return '';
	return date($arr[$t],$d);
}

function dump($var, $echo=true, $label=null, $strict=true) {
    $label = ($label === null) ? '' : rtrim($label) . ' ';
    if (!$strict) {
        if (ini_get('html_errors')) {
            $output = print_r($var, true);
            $output = '<pre>' . $label . htmlspecialchars($output, ENT_QUOTES) . '</pre>';
        } else {
            $output = $label . print_r($var, true);
        }
    } else {
        ob_start();
        var_dump($var);
        $output = ob_get_clean();
        if (!extension_loaded('xdebug')) {
            $output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output);
            $output = '<pre>' . $label . htmlspecialchars($output, ENT_QUOTES) . '</pre>';
        }
    }
    if ($echo) {
        echo($output);
        return null;
    }else
        return $output;
}


function menuval($s,$v,$l){
$menus1=array("prizelist","tiqulist","chonglist","zhuanlist","huanlist");
$menus2=array("register","tumap","anmap","mytj");
$menus3=array("openlist","bdshen");
$menus4=array("myinfo","modpwd","modmb","mybank","myuplevel");
$menus5=array("liuyan","sjx","fjx","yjx");
if($l==0){
    $l1="active";
    $l2="normal";
}else{
    $l1="";
    $l2="none";
}

switch ($v) {
    case 1:

        if(in_array($_GET["yim"], $menus1)) 
            return $l1;
        else
            return $l2;
    
    break;
    case 2:
     	if(empty($_GET["yim"])){
    		 return $l1;

    	}else{
   
        if(in_array($_GET["yim"], $menus2)) 
            return $l1;
        else
            return $l2;
    	}
    break;   
    case 3:
        if(in_array($_GET["yim"], $menus3)) 
            return $l1;
        else
            return $l2;
    break;   
    case 4:
        if(in_array($_GET["yim"], $menus4)) 
            return $l1;
        else
            return $l2;
    break;            
    case 5:
        if(in_array($_GET["yim"], $menus5)) 
            return $l1;
        else
            return $l2;
    break;   

}

}


function getrealip()
{
    static $realip = NULL;

    if ($realip !== NULL)
    {
        return $realip;
    }

    if (isset($_SERVER))
    {
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
        {
            $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);

            /* 取X-Forwarded-For中第一个非unknown的有效IP字符串 */
            foreach ($arr AS $ip)
            {
                $ip = trim($ip);

                if ($ip != 'unknown')
                {
                    $realip = $ip;

                    break;
                }
            }
        }
        elseif (isset($_SERVER['HTTP_CLIENT_IP']))
        {
            $realip = $_SERVER['HTTP_CLIENT_IP'];
        }
        else
        {
            if (isset($_SERVER['REMOTE_ADDR']))
            {
                $realip = $_SERVER['REMOTE_ADDR'];
            }
            else
            {
                $realip = '0.0.0.0';
            }
        }
    }
    else
    {
        if (getenv('HTTP_X_FORWARDED_FOR'))
        {
            $realip = getenv('HTTP_X_FORWARDED_FOR');
        }
        elseif (getenv('HTTP_CLIENT_IP'))
        {
            $realip = getenv('HTTP_CLIENT_IP');
        }
        else
        {
            $realip = getenv('REMOTE_ADDR');
        }
    }

    preg_match("/[\d\.]{7,15}/", $realip, $onlineip);
    $realip = !empty($onlineip[0]) ? $onlineip[0] : '0.0.0.0';

    return $realip;
}	
/**
 * 数组分页函数 
 * 用此函数之前要先将数据库里面的所有数据按一定的顺序查询出来存入数组中
 * $count  每页多少条数据
 * $page  当前第几页
 * $array  查询出来的所有数组
 * order 0 - 不变   1- 反序
 */

 #################测试用list########


############################################################
function page_array($count,$page,$array,$order=0){
  global $countpage; #定全局变量
  
  $page=(empty($page))?'1':$page; #判断当前页面是否为空 如果为空就表示为第一页面 
    $start=($page-1)*$count; #计算每次分页的开始位置
  if($order==1){
   $array=array_reverse($array);
  }  
  $totals=count($array); 
  $countpage=ceil($totals/$count); #计算总页面数
  $pagedata=array();
 $pagedata=array_slice($array,$start,$count);
  return $pagedata; #返回查询数据
}
/**
 * 分页及显示函数
 * $countpage 全局变量，照写
 * $url 当前url
 */
function show_array(){
 $countpage=$GLOBALS['countpage'];
 $url=$_SERVER['REQUEST_URI'];
 //--------------处理url,防止出现多次的&page=n -------------------
 $deli='?';   //page前分隔符，？或者&
 /**/
 if(strpos($url,'?page')||strpos($url,'&page')){  //如果链接已经包含page参数
	if(strpos($url,'?page')){                     //如果链接 是url?page= 类型  
		$url=strstr($url,'?page',true);
		$deli='?';
		//echo '走？page<hr />';
	}else if(strpos($url,'&page')){                     //如果是url?mod=''&page= 类型，去掉url 中的&page=，重新添加
		$url=strstr($url,'&page',true);
		
		$deli='&';
		//echo $url,'走&page<hr />';
	}
 }else if(strpos($url,'?')){                      //如果是url?mod=''
	$deli='&';
	//echo '走？<hr />';
 }else{
	$deli='?'; 
	//echo '走空白<hr />';//如果是不含参数url类型
 }
 
 //--------------处理url结束----------------------------------------
   $page=empty($_GET['page'])?1:$_GET['page'];
 if($page > 1){
   $uppage=$page-1;
 }else{
  $uppage=1;
 }
 if($page < $countpage){
   $nextpage=$page+1;
 
 }else{
   $nextpage=$countpage;
 }

 #改进的分页方式
$str='<br /><ul>';
$str.="<li><a href='{$url}{$deli}page=1'>首页</a></li>";
$str.="<li><a href='{$url}{$deli}page={$uppage}'> << </a></li>";

if($countpage<=7){
    $begin=1;
    $end=$countpage;
}else if($page<=4){
    $begin=1;
    $end=7;
}else if($page+3>$countpage){
    $begin=$countpage-6;
    $end=$countpage;
}else{
    $begin=$page-3;
    $end=$page+3;
}


for($i=$begin;$i<=$end;$i++){
    if($_GET['page']==$i){
        $bg='background-color:RGB(0,159,199)';
        $co='color:white';
    }else if(empty($_GET['page'])&&($i==1)){
        $bg='background-color:RGB(0,159,199)';
        $co='color:white';
    }else{
        $bg='';
        $co='';
    }
    $str.="<li style='$bg'><a style='$co' href='{$url}{$deli}page=$i'>$i</a></li>";
    
    
}
$str.="<li><a href='{$url}{$deli}page={$nextpage}'> >> </a></li>";
$str.="<li><a href='{$url}{$deli}page=$countpage'>尾页</a></li></ul>";



 return $str;
}
function encorder($order_no){
	$fenmiao = substr($order_no,-4);
	$shi1 = substr($order_no,8,1);
	$shi2 = substr($order_no,9,1);
	$day1 = substr($order_no,6,1);
	$day2 = substr($order_no,7,1);
	$yue1 = substr($order_no,4,1);
	$yue2 = substr($order_no,5,1);
	$year = substr($order_no,0,4);
	return $shi2.$yue1.$fenmiao.$day1.$shi1.$yue2.$year.$day2;
}
function dncorder($order_no){
	$fenmiao = substr($order_no,2,4);
	$shi1 = substr($order_no,7,1);
	$shi2 = substr($order_no,0,1);
	$day1 = substr($order_no,6,1);
	$day2 = substr($order_no,-1);
	$yue1 = substr($order_no,1,1);
	$yue2 = substr($order_no,8,1);
	$year = substr($order_no,9,4);
	return $year.$yue1.$yue2.$day1.$day2.$shi1.$shi2.$fenmiao;
}
function get_help_no($type,$uname,$help_no){
	if($type == "give"){
		$helpno1 = str_replace($uname,'',$help_no);
		return "T".encorder($helpno1);
	}elseif($type == "get"){
		$helpno1 = str_replace($uname,'',$help_no);
		return "D".encorder($helpno1);
	}
}
function testmuma($test){
	if(strstr($test,"php")||strstr($test,"PHP")||strstr($test,"asp")||strstr($test,"ASP")||strstr($test,"POST")||strstr($test,"GET")||strstr($test,"request")||strstr($test,"eval")||strstr($test,"REQUEST")||strstr($test,"EVAL")||strstr($test,"execute")||strstr($test,"EXECUTE")||strstr($test,"preg_replace")||strstr($test,"$_POST")||strstr($test,"$_GET")||strstr($test,"insert")||strstr($test,"INSERT")||strstr($test,"update")||strstr($test,"UPDATE")||strstr($test,"PREG_REPLACE")){
		return true;
	}else{
		return false;
	}
}
function regex($value,$rule) {
	$validate = array(
		'require'   =>  '/.+/',
		'email'     =>  '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',
		'url'       =>  '/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/',
		'currency'  =>  '/^\d+(\.\d+)?$/',
		'number'    =>  '/^\d+$/',
		'zip'       =>  '/^\d{6}$/',
		'integer'   =>  '/^[-\+]?\d+$/',
		'double'    =>  '/^[-\+]?\d+(\.\d+)?$/',
		'english'   =>  '/^[A-Za-z]+$/',
	);
	// 检查是否有内置的正则表达式
	if(isset($validate[strtolower($rule)]))
		$rule       =   $validate[strtolower($rule)];
	return preg_match($rule,$value)===1;
}
function setgoodscart($productid,$productname,$num,$price,$pv,$shopname){
	$goodscartstr=getgoodscart();
	$goodscartstr_1="";$goodscartexist=0;
	$gstr=$productid.",".$productname.",".$num.",".$price.",".$pv.",".$shopname;
	if (empty($goodscartstr)){
		$goodscartstr_1=$gstr;
	}else{
		$goodscartary=explode("|",$goodscartstr);
		foreach($goodscartary as $value_1){
			$value_1_ary=explode(",",$value_1);
			if ($value_1_ary[0]==$productid){
				$goodscartexist=1;
				$gstr2=$value_1_ary[0].",".$value_1_ary[1].",".($value_1_ary[2]+$num).",".$value_1_ary[3].",".$value_1_ary[4].",".$value_1_ary[5];
				if ($goodscartstr_1!="") $goodscartstr_1.="|";
				$goodscartstr_1.=$gstr2;
			}else{
				$gstr1=$value_1_ary[0].",".$value_1_ary[1].",".$value_1_ary[2].",".$value_1_ary[3].",".$value_1_ary[4].",".$value_1_ary[5];
				if ($goodscartstr_1!="") $goodscartstr_1.="|";
				$goodscartstr_1.=$gstr1;
			}
		}
		if ($goodscartexist==0){
			if ($goodscartstr_1!="") $goodscartstr_1.="|";
			$goodscartstr_1.=$gstr;
		}
	}
	setcookie("glo_goodscart",$goodscartstr_1);
}
function getgoodscart(){
	return $_COOKIE["glo_goodscart"];
}
function cleargoodscart(){
	setcookie("glo_goodscart","");
}
function delgoodscart($productid){
	$goodscartstr=getgoodscart();
	$goodscartstr_1="";
	if (empty($goodscartstr)){
		//do nothing
	}else{
		$goodscartary=explode("|",$goodscartstr);
		foreach($goodscartary as $value_1){
			$value_1_ary=explode(",",$value_1);
			if ($value_1_ary[0]==$productid){
				//do nothing
			}else{
				$gstr=$value_1_ary[0].",".$value_1_ary[1].",".$value_1_ary[2].",".$value_1_ary[3].",".$value_1_ary[4].",".$value_1_ary[5];
				if ($goodscartstr_1!="") $goodscartstr_1.="|";
				$goodscartstr_1.=$gstr;
			}
		}
	}
	setcookie("glo_goodscart",$goodscartstr_1);
}
function editgoodscart($productid,$productname,$num,$price,$pv){
	$goodscartstr=getgoodscart();
	$goodscartstr_1="";
	if (empty($goodscartstr)){
		$goodscartstr_1=$gstr;
	}else{
		$goodscartary=explode("|",$goodscartstr);
		foreach($goodscartary as $value_1){
			$value_1_ary=explode(",",$value_1);
			if ($value_1_ary[0]==$productid){
				$gstr2=$value_1_ary[0].",".$value_1_ary[1].",".$num.",".$value_1_ary[3].",".$value_1_ary[4].",".$value_1_ary[5];
				if ($goodscartstr_1!="") $goodscartstr_1.="|";
				$goodscartstr_1.=$gstr2;
			}else{
				$gstr1=$value_1_ary[0].",".$value_1_ary[1].",".$value_1_ary[2].",".$value_1_ary[3].",".$value_1_ary[4].",".$value_1_ary[5];
				if ($goodscartstr_1!="") $goodscartstr_1.="|";
				$goodscartstr_1.=$gstr1;
			}
		}
	}
	setcookie("glo_goodscart",$goodscartstr_1);
}
?>
<?php
function setgoodscart1($productid,$productname,$num,$price,$pv,$shopname){
	$goodscartstr=getgoodscart();
	$goodscartstr_1="";$goodscartexist=0;
	$gstr=$productid.",".$productname.",".$num.",".$price.",".$pv.",".$shopname;
	if (empty($goodscartstr)){
		$goodscartstr_1=$gstr;
	}else{
		$goodscartary=explode("|",$goodscartstr);
		foreach($goodscartary as $value_1){
			$value_1_ary=explode(",",$value_1);
			if ($value_1_ary[0]==$productid){
				$goodscartexist=1;
				$gstr2=$value_1_ary[0].",".$value_1_ary[1].",".($value_1_ary[2]+$num).",".$value_1_ary[3].",".$value_1_ary[4].",".$value_1_ary[5];
				if ($goodscartstr_1!="") $goodscartstr_1.="|";
				$goodscartstr_1.=$gstr2;
			}else{
				$gstr1=$value_1_ary[0].",".$value_1_ary[1].",".$value_1_ary[2].",".$value_1_ary[3].",".$value_1_ary[4].",".$value_1_ary[5];
				if ($goodscartstr_1!="") $goodscartstr_1.="|";
				$goodscartstr_1.=$gstr1;
			}
		}
		if ($goodscartexist==0){
			if ($goodscartstr_1!="") $goodscartstr_1.="|";
			$goodscartstr_1.=$gstr;
		}
	}
	setcookie("glo_goodscart",$goodscartstr_1);
}
function getgoodscart1(){
	return $_COOKIE["glo_goodscart"];
}
function cleargoodscart1(){
	setcookie("glo_goodscart","");
}
function delgoodscart1($productid){
	$goodscartstr=getgoodscart();
	$goodscartstr_1="";
	if (empty($goodscartstr)){
		//do nothing
	}else{
		$goodscartary=explode("|",$goodscartstr);
		foreach($goodscartary as $value_1){
			$value_1_ary=explode(",",$value_1);
			if ($value_1_ary[0]==$productid){
				//do nothing
			}else{
				$gstr=$value_1_ary[0].",".$value_1_ary[1].",".$value_1_ary[2].",".$value_1_ary[3].",".$value_1_ary[4].",".$value_1_ary[5];
				if ($goodscartstr_1!="") $goodscartstr_1.="|";
				$goodscartstr_1.=$gstr;
			}
		}
	}
	setcookie("glo_goodscart",$goodscartstr_1);
}
function editgoodscart1($productid,$productname,$num,$price,$pv){
	$goodscartstr=getgoodscart();
	$goodscartstr_1="";
	if (empty($goodscartstr)){
		$goodscartstr_1=$gstr;
	}else{
		$goodscartary=explode("|",$goodscartstr);
		foreach($goodscartary as $value_1){
			$value_1_ary=explode(",",$value_1);
			if ($value_1_ary[0]==$productid){
				$gstr2=$value_1_ary[0].",".$value_1_ary[1].",".$num.",".$value_1_ary[3].",".$value_1_ary[4].",".$value_1_ary[5];
				if ($goodscartstr_1!="") $goodscartstr_1.="|";
				$goodscartstr_1.=$gstr2;
			}else{
				$gstr1=$value_1_ary[0].",".$value_1_ary[1].",".$value_1_ary[2].",".$value_1_ary[3].",".$value_1_ary[4].",".$value_1_ary[5];
				if ($goodscartstr_1!="") $goodscartstr_1.="|";
				$goodscartstr_1.=$gstr1;
			}
		}
	}
	setcookie("glo_goodscart",$goodscartstr_1);
}
function RemoveXSS($val) {
   $val = preg_replace('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/', '', $val);  
   $search = 'abcdefghijklmnopqrstuvwxyz'; 
   $search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';  
   $search .= '1234567890!@#$%^&*()'; 
   $search .= '~`";:?+/={}[]-_|\'\\'; 
   for ($i = 0; $i < strlen($search); $i++) { 
      // ;? matches the ;, which is optional 
      // 0{0,7} matches any padded zeros, which are optional and go up to 8 chars 
 
      // @ @ search for the hex values 
      $val = preg_replace('/(&#[xX]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val); // with a ; 
      // @ @ 0{0,7} matches '0' zero to seven times  
      $val = preg_replace('/(&#0{0,8}'.ord($search[$i]).';?)/', $search[$i], $val); // with a ; 
   } 
 
   // now the only remaining whitespace attacks are \t, \n, and \r 
   $ra1 = Array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base'); 
   $ra2 = Array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload'); 
   $ra = array_merge($ra1, $ra2); 
 
   $found = true; // keep replacing as long as the previous round replaced something 
   while ($found == true) { 
      $val_before = $val; 
      for ($i = 0; $i < sizeof($ra); $i++) { 
         $pattern = '/'; 
         for ($j = 0; $j < strlen($ra[$i]); $j++) { 
            if ($j > 0) { 
               $pattern .= '(';  
               $pattern .= '(&#[xX]0{0,8}([9ab]);)'; 
               $pattern .= '|';  
               $pattern .= '|(&#0{0,8}([9|10|13]);)'; 
               $pattern .= ')*'; 
            } 
            $pattern .= $ra[$i][$j]; 
         } 
         $pattern .= '/i';  
         $replacement = substr($ra[$i], 0, 2).'<x>'.substr($ra[$i], 2); // add in <> to nerf the tag  
         $val = preg_replace($pattern, $replacement, $val); // filter out the hex tags  
         if ($val_before == $val) {  
            // no replacements were made, so exit the loop  
            $found = false;  
         }  
      }  
   }  
   return $val;  
}
//PHP 程序调试函数
function dd($str = 0)
{
    if (is_array($str) || is_object($str)) {
        echo "<pre>";
        var_dump($str);
        echo "</pre>";
        die;
    } else {
        echo "<pre>{$str}</pre>";
        exit;
    }
}

?>

   
